package com.csx.springcloud.invoke.openfeign.provider.controller;

import com.csx.springcloud.invoke.openfeign.api.ProviderApi;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p> what does this class do ? </p>
 * <p> How does it work ?</p>
 * <p> Why does it do this ?</p>
 *
 * @author cuisongxu
 * @date 2023/8/5 周六 14:40
 */

@RequestMapping("/provider")
@RestController
public class OpenFeignProviderController implements ProviderApi {


    /**
     * 1. 测试 Feign 的基本使用
     */
    @GetMapping("/getUsername")
    public String getUsername() {
        return "zhangsan";
    }

    /**
     * 2. 测试 超时调用
     */
    @GetMapping("/testTimeout")
    public String testTimeout() {

        try {
            // 模拟网络延时
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "testTimeout";
    }

    /**
     * 3. 测试 业务异常
     */
    @GetMapping("/testException")
    public String testException() {

        // 模拟业务异常
        throw new RuntimeException("test Exception");
    }

    @GetMapping("/testFallback")
    public String testFallback() {

        // 模拟业务异常
        throw new RuntimeException("test Fallback");
    }

}
